package hive.ch1.test1;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class MRCountDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

//      Other path:
//      input path: hdfs://liu:9000/hive/input
//      output path: hdfs://liu:9000/hive/output
        Configuration configuration = new Configuration();
        configuration.set("fs.defaultFS", "hdfs://liu:9000");

        Job job = Job.getInstance(configuration);

        job.setMapperClass(MRCountMapper.class);
        job.setReducerClass(MRCountReducer.class);
        job.setJarByClass(MRCountDriver.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
